<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="###Android OpenGL 使用  基本框架编写一个类来继承GLSurfaceView.Renderer，并实现其中的三个方法onSurfaceCreated、onSurfaceChanged、onDrawFrame。123456789101112131415161718192021222324252627282930313233343536373839404142434445464748">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="Android-OpenGL-使用">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/Android/Android-OpenGL-使用/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="###Android OpenGL 使用  基本框架编写一个类来继承GLSurfaceView.Renderer，并实现其中的三个方法onSurfaceCreated、onSurfaceChanged、onDrawFrame。123456789101112131415161718192021222324252627282930313233343536373839404142434445464748">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-2b7eda78906d9472.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-0c1bcb70ef5a7564.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-22e4ccf5d27a103f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-5c08444a58ddfebc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-b31c7393b4dd12a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-08-06T11:21:39.773Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android-OpenGL-使用">
<meta name="twitter:description" content="###Android OpenGL 使用  基本框架编写一个类来继承GLSurfaceView.Renderer，并实现其中的三个方法onSurfaceCreated、onSurfaceChanged、onDrawFrame。123456789101112131415161718192021222324252627282930313233343536373839404142434445464748">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/3110861-2b7eda78906d9472.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/Android/Android-OpenGL-使用/"/>





  <title>Android-OpenGL-使用 | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/Android/Android-OpenGL-使用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android-OpenGL-使用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>###Android OpenGL 使用</p>
<ol>
<li>基本框架<br>编写一个类来继承GLSurfaceView.Renderer，并实现其中的三个方法onSurfaceCreated、onSurfaceChanged、onDrawFrame。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 基本框架</span><br><span class="line"> * Created by mazaiting on 2017/8/9.</span><br><span class="line"> */</span><br><span class="line">public class GLRenderer implements GLSurfaceView.Renderer &#123;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">   * 在窗口被创建时被调用，需要做一些必要的初始化工作:</span><br><span class="line">   */</span><br><span class="line">  @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) &#123;</span><br><span class="line">    // 启动阴影平滑</span><br><span class="line">    gl.glShadeModel(GL10.GL_SMOOTH);</span><br><span class="line">    // 黑色背景，设置清楚屏幕时所用的颜色取值：RGBA.0f-1.0f</span><br><span class="line">    gl.glClearColor(0, 0, 0, 1.0f);</span><br><span class="line">    // 设置深度缓存--决定哪个物体先画</span><br><span class="line">    gl.glClearDepthf(1.0f);</span><br><span class="line">    // 启动深度测试</span><br><span class="line">    gl.glEnable(GL10.GL_DEPTH_TEST);</span><br><span class="line">    // 所作深度测试的类型</span><br><span class="line">    gl.glDepthFunc(GL10.GL_LEQUAL);</span><br><span class="line">    // 告诉系统对透视进行修正</span><br><span class="line">    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">   * 当窗口大小发生改变时被调用，不管窗口的大小是否已经改变，在程序开始时至少运行一次。</span><br><span class="line">   */</span><br><span class="line">  @Override public void onSurfaceChanged(GL10 gl, int width, int height) &#123;</span><br><span class="line">    float ratio = (float) width / height;</span><br><span class="line">    // 设置OpenGL场景的大小</span><br><span class="line">    gl.glViewport(0, 0, width, height);</span><br><span class="line">    // 设置投影矩阵--增加透视</span><br><span class="line">    gl.glMatrixMode(GL10.GL_PROJECTION);</span><br><span class="line">    // 重置投影矩阵--恢复原始状态</span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">    // 设置视图的大小</span><br><span class="line">    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);</span><br><span class="line">    // 选择模型观察矩阵</span><br><span class="line">    gl.glMatrixMode(GL10.GL_MODELVIEW);</span><br><span class="line">    // 重置模型观察矩阵</span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">   * 在窗口内进行绘图操作。 在绘图之前，需要将屏幕清楚成前面指定的颜色，清楚深度缓存并且重置场景</span><br><span class="line">   */</span><br><span class="line">  @Override public void onDrawFrame(GL10 gl) &#123;</span><br><span class="line">    // 清楚屏幕和深度缓存</span><br><span class="line">    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);</span><br><span class="line">    // 重置当前的模型观察矩阵</span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">    // 具体绘图开始...</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">     * OpenGL 是一个非常底层的画图接口，它所使用的缓冲区存储结构是和我们的 java 程序中不相同的。</span><br><span class="line">     * Java 是大端字节序(BigEdian)，而 OpenGL 所需要的数据是小端字节序(LittleEdian)。</span><br><span class="line">     * 所以，我们在将 Java 的缓冲区转化为 OpenGL 可用的缓冲区时需要作一些工作。建立buff的方法如下</span><br><span class="line">     **/</span><br><span class="line">  public Buffer bufferUtil(int []arr)&#123;</span><br><span class="line">    // 先初始化buffer,数组的长度*4,因为一个int占4个字节</span><br><span class="line">    ByteBuffer qbb = ByteBuffer.allocateDirect(arr.length * 4);</span><br><span class="line">    // 数组排列用nativeOrder</span><br><span class="line">    qbb.order(ByteOrder.nativeOrder());</span><br><span class="line">    // 将ByteBuffer转换为IntBuffer</span><br><span class="line">    IntBuffer mBuffer = qbb.asIntBuffer();</span><br><span class="line">    // 将数组设置进去</span><br><span class="line">    mBuffer.put(arr);</span><br><span class="line">    //mBuffer.position(0);</span><br><span class="line">    // 重置</span><br><span class="line">    mBuffer.flip();</span><br><span class="line">    return mBuffer;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<a id="more"></a>
<p>其中都是一些具体的配置，在主Activity中，我们首先创建出一个GLRenderer对象 ，并创建GLSurfaceView对象，将GLRenderer对象设置在GLSurfaceView对象中。、<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">public class MainActivity extends AppCompatActivity &#123;</span><br><span class="line"></span><br><span class="line">  @Override protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">    super.onCreate(savedInstanceState);</span><br><span class="line"></span><br><span class="line">    // 基础框架</span><br><span class="line">    GLSurfaceView.Renderer renderer = new GLRenderer();</span><br><span class="line">    GLSurfaceView glView = new GLSurfaceView(this);</span><br><span class="line">    glView.setRenderer(renderer);</span><br><span class="line">    // 设置布局</span><br><span class="line">    setContentView(glView);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>至此，我们将OpenGL开发时所要做的配置已完成，接下来我们在写新的Renderer时，只需要继承在GLRenderer，重写onDrawFrame(GL10 gl)方法即可。</p>
<ol start="2">
<li>绘制多边形<br>实现此类后，要想看到效果，务必将主Acitivity<code>GLSurfaceView.Renderer renderer = new GLRenderer();</code>的此行代码更改为<code>GLSurfaceView.Renderer renderer = new PolygonRenderer();</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 绘制多边形</span><br><span class="line"> * Created by mazaiting on 2017/8/9.</span><br><span class="line"> */</span><br><span class="line">public class PolygonRenderer extends GLRenderer&#123;</span><br><span class="line">  int one = 0x00010000;</span><br><span class="line">  //三角形三个顶点</span><br><span class="line">  private int[] triggerBuffer = new int[] &#123;</span><br><span class="line">      0, one, 0,//上顶点</span><br><span class="line">      - one, -one, 0, //左下点</span><br><span class="line">      one, -one, 0,&#125;; //右下点</span><br><span class="line"></span><br><span class="line">  //正方形的4个顶点</span><br><span class="line">  private int[] quaterBuffer = new int[]&#123;</span><br><span class="line">      one,one,0,</span><br><span class="line">      -one,one,0,</span><br><span class="line">      one,-one,0,</span><br><span class="line">      -one,-one,0&#125;;</span><br><span class="line"></span><br><span class="line">  @Override public void onDrawFrame(GL10 gl) &#123;</span><br><span class="line">    super.onDrawFrame(gl);</span><br><span class="line">    // 此函数，就是将画笔沿X轴左移1.5f个单位，Y轴保持不变，Z轴向屏幕里面移动6.0f个单位。</span><br><span class="line">    //gl.glTranslatef(-1.5f, 0.0f, -6.0f);</span><br><span class="line">    // 左移 1.5 单位，并移入屏幕 6.0</span><br><span class="line">    gl.glTranslatef(-1.5f, 0.0f, -6.0f);// z 轴值小于-1.0f</span><br><span class="line">    // 允许设置顶点</span><br><span class="line">    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">    // 设置三角形</span><br><span class="line">    gl.glVertexPointer(3, GL10.GL_FIXED, 0, bufferUtil(triggerBuffer));</span><br><span class="line">    // 绘制三角形</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);</span><br><span class="line"></span><br><span class="line">    // 重置当前模型观察矩阵</span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">    // 右移 1.5 单位，并移入屏幕 6.0</span><br><span class="line">    gl.glTranslatef(1.5f, 0.0f, -6.0f);// z 轴值小于-1.0f</span><br><span class="line">    // 设置四边形</span><br><span class="line">    gl.glVertexPointer(3,GL10.GL_FIXED,0,bufferUtil(quaterBuffer));</span><br><span class="line">    // 绘制四边形</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,4);</span><br><span class="line">    //取消顶点设置</span><br><span class="line">    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">    // 重置当前的模型观察矩阵</span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>效果图：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/3110861-2b7eda78906d9472.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="绘制多边形.png"></p>
<ol start="3">
<li>绘制颜色<br>实现此类后，要想看到效果，务必将主Acitivity<code>GLSurfaceView.Renderer renderer = new GLRenderer();</code>的此行代码更改为<code>GLSurfaceView.Renderer renderer = new ColorRenderer();</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 绘制颜色</span><br><span class="line"> * Created by mazaiting on 2017/8/9.</span><br><span class="line"> */</span><br><span class="line">public class ColorRenderer extends GLRenderer &#123;</span><br><span class="line">  int one = 0x10000;</span><br><span class="line">  //三角形三个顶点 （r,g,b,a)</span><br><span class="line">  private int[] triggerBuffer = new int[] &#123;</span><br><span class="line">      0, one, 0,//上顶点</span><br><span class="line">      - one, -one, 0, //左下点</span><br><span class="line">      one, -one, 0,&#125;; //右下点</span><br><span class="line"></span><br><span class="line">  //正方形的4个顶点</span><br><span class="line">  private int[] quaterBuffer = new int[]&#123;</span><br><span class="line">      one,one,0,</span><br><span class="line">      -one,one,0,</span><br><span class="line">      one,-one,0,</span><br><span class="line">      -one,-one,0&#125;;</span><br><span class="line">  //三角形的顶点颜色值(r,g,b,a)</span><br><span class="line">  private int[] colorBuffer = new int[]&#123;</span><br><span class="line">      one,0,0,one,</span><br><span class="line">      0,one,0,one,</span><br><span class="line">      0,0,one,one,</span><br><span class="line">      &#125;;</span><br><span class="line"></span><br><span class="line">  @Override public void onDrawFrame(GL10 gl) &#123;</span><br><span class="line">    super.onDrawFrame(gl);</span><br><span class="line">    // 左移 1.5 单位，并移入屏幕 6.0</span><br><span class="line">    gl.glTranslatef(-1.5f,0.0f,-6.0f);</span><br><span class="line">    //设置定点数组</span><br><span class="line">    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">    //设置颜色数组 -- 开启颜色渲染功能.</span><br><span class="line">    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);</span><br><span class="line">    // 设置三角形顶点的颜色</span><br><span class="line">    gl.glColorPointer(4,GL10.GL_FIXED,0,bufferUtil(colorBuffer));</span><br><span class="line">    // 设置三角形顶点</span><br><span class="line">    gl.glVertexPointer(3,GL10.GL_FIXED,0,bufferUtil(triggerBuffer));</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLES,0,3);</span><br><span class="line">    //关闭颜色数组 -- 关闭颜色渲染功能.</span><br><span class="line">    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);</span><br><span class="line"></span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">    // 右移 1.5 单位，并移入屏幕 6.0</span><br><span class="line">    gl.glTranslatef(1.5f,0.0f,-6.0f);</span><br><span class="line">    // 设置当前色为蓝色</span><br><span class="line">    gl.glColor4f(0.0f,0.5f,1.0f,1.0f);</span><br><span class="line">    //设置和绘制正方形</span><br><span class="line">    gl.glVertexPointer(3,GL10.GL_FIXED,0,bufferUtil(quaterBuffer));</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,4);</span><br><span class="line">    //取消顶点数组</span><br><span class="line">    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>效果图：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/3110861-0c1bcb70ef5a7564.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="绘制颜色.png"></p>
<ol start="4">
<li>绘制旋转<br>实现此类后，要想看到效果，务必将主Acitivity<code>GLSurfaceView.Renderer renderer = new GLRenderer();</code>的此行代码更改为<code>GLSurfaceView.Renderer renderer = new RotateRenderer();</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 绘制旋转图形</span><br><span class="line"> * Created by mazaiting on 2017/8/9.</span><br><span class="line"> */</span><br><span class="line">public class RotateRenderer extends GLRenderer &#123;</span><br><span class="line">  int one = 0x00010000;</span><br><span class="line">  //三角形三个顶点</span><br><span class="line">  private int[] triggerBuffer = new int[] &#123;</span><br><span class="line">      0, one, 0,//上顶点</span><br><span class="line">      - one, -one, 0, //左下点</span><br><span class="line">      one, -one, 0,&#125;; //右下点</span><br><span class="line"></span><br><span class="line">  @Override public void onDrawFrame(GL10 gl) &#123;</span><br><span class="line">    super.onDrawFrame(gl);</span><br><span class="line"></span><br><span class="line">    gl.glTranslatef(-1.5f,0.0f,-6.0f);</span><br><span class="line">    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">    gl.glRotatef(180f,0,0,0);//旋转180</span><br><span class="line">    gl.glVertexPointer(3,GL10.GL_FIXED,0,bufferUtil(triggerBuffer));</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLES,0,3);</span><br><span class="line">    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">    gl.glLoadIdentity();</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>效果图：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/3110861-22e4ccf5d27a103f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="绘制旋转.png"></p>
<ol start="5">
<li>绘制三棱锥<br>实现此类后，要想看到效果，务必将主Acitivity<code>GLSurfaceView.Renderer renderer = new GLRenderer();</code>的此行代码更改为<code>GLSurfaceView.Renderer renderer = new PyramidRenderer();</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 四棱锥</span><br><span class="line"> * Created by mazaiting on 2017/8/9.</span><br><span class="line"> */</span><br><span class="line"></span><br><span class="line">public class PyramidRenderer extends GLRenderer &#123;</span><br><span class="line">  int one = 0x10000;</span><br><span class="line"></span><br><span class="line">  // 四棱锥顶点数组:</span><br><span class="line">  private int[] triggerBuffer = new int[] &#123;</span><br><span class="line">      0, one, 0,</span><br><span class="line">      -one, -one, one,</span><br><span class="line">      one, -one, one,</span><br><span class="line"></span><br><span class="line">      0,one, 0,</span><br><span class="line">      one,-one, one,</span><br><span class="line">      one, -one, -one,</span><br><span class="line"></span><br><span class="line">      0, one, 0,</span><br><span class="line">      one, -one, -one,</span><br><span class="line">      -one, -one, -one,</span><br><span class="line"></span><br><span class="line">      0, one, 0,</span><br><span class="line">      -one, -one, -one,</span><br><span class="line">      -one, -one, one</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">   * Every vertex has got its own color, described by 4 values</span><br><span class="line">   * R(ed)</span><br><span class="line">   * G(green)</span><br><span class="line">   * B(blue)</span><br><span class="line">   * A(lpha)</span><br><span class="line">   */</span><br><span class="line">  int colors[] = &#123;</span><br><span class="line">      0, 0, 0, one, one, 0, 0, one, one, one, 0, one, 0, one, 0, one, 0, 0, one, one, one, 0, one,</span><br><span class="line">      one, one, one, one, one, 0, one, one, one,</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">   * The last thing is that we need to describe some Triangles.</span><br><span class="line">   * A triangle got 3 vertices.</span><br><span class="line">   * The confusing thing is, that it is important in which order</span><br><span class="line">   * the vertices of each triangle are described.</span><br><span class="line">   * So describing a triangle through the vertices: &quot;0, 4, 5&quot;</span><br><span class="line">   * will not result in the same triangle as: &quot;0, 5, 4&quot;</span><br><span class="line">   * You probably ask: Why the hell isn&apos;t that the same ???</span><br><span class="line">   * The reason for that is the call of: &quot;gl.glFrontFace(gl.GL_CW);&quot;</span><br><span class="line">   * which means, that we have to describe the &quot;visible&quot; side of the</span><br><span class="line">   * triangles by naming its vertices in a ClockWise order!</span><br><span class="line">   * From the other side, the triangle will be 100% lookthru!</span><br><span class="line">   * You can create a kind of magic mirror with that</span><br><span class="line">   **/</span><br><span class="line">  byte indices[] = &#123;</span><br><span class="line">      0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3,</span><br><span class="line">      0, 1, 3, 1, 2</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  @Override public void onSurfaceChanged(GL10 gl, int width, int height) &#123;</span><br><span class="line">    super.onSurfaceChanged(gl, width, height);</span><br><span class="line">    // 设置透视范围</span><br><span class="line">    GLU.gluPerspective(gl, 45.0f, ((float) width) / height, 0.1f, 10f);</span><br><span class="line">  &#125;</span><br><span class="line">  float xRot = 0.0f;</span><br><span class="line">  float yRot = 0.0f;</span><br><span class="line">  @Override public void onDrawFrame(GL10 gl) &#123;</span><br><span class="line">    super.onDrawFrame(gl);</span><br><span class="line">    gl.glMatrixMode(GL10.GL_MODELVIEW);// 切换至模型观察矩阵</span><br><span class="line">    gl.glLoadIdentity();// 重置当前的模型观察矩阵</span><br><span class="line">    GLU.gluLookAt(gl, 0f, 0f, 3f, 0f, 0f, 0f, 0f, 1f, 0f);//设置视点和模型中心位置</span><br><span class="line"></span><br><span class="line">    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line">    gl.glVertexPointer(3, GL10.GL_FIXED, 0, bufferUtil(triggerBuffer));</span><br><span class="line">    gl.glRotatef(xRot,1f,0f,0f);// 绕着(0,0,0)与(1,0,0)即x轴旋转</span><br><span class="line">    gl.glRotatef(yRot,0f,1f,0f);</span><br><span class="line"></span><br><span class="line">    gl.glColor4f(1.0f,0.0f,0.0f,1.0f);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 3);</span><br><span class="line">    gl.glColor4f(0.0f,1.0f,0.0f,1.0f);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 3, 3);</span><br><span class="line">    gl.glColor4f(0.0f,0.0f,1.0f,1.0f);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 6, 3);</span><br><span class="line">    gl.glColor4f(1.0f,0.0f,1.0f,1.0f);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 9, 3);</span><br><span class="line"></span><br><span class="line">    xRot += 1.0f;</span><br><span class="line">    yRot += 0.5f;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>效果图：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/3110861-5c08444a58ddfebc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="三棱锥.png"></p>
<ol start="5">
<li>绘制正方体<br>实现此类后，要想看到效果，务必将主Acitivity<code>GLSurfaceView.Renderer renderer = new GLRenderer();</code>的此行代码更改为<code>GLSurfaceView.Renderer renderer = new CubeRenderer();</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 绘制正方体</span><br><span class="line"> * Created by mazaiting on 2017/8/10.</span><br><span class="line"> */</span><br><span class="line">public class CubeRenderer extends GLRenderer&#123;</span><br><span class="line"></span><br><span class="line">  float box[] = new float[] &#123;</span><br><span class="line">      // FRONT</span><br><span class="line">      -0.5f, -0.5f,  0.5f,</span><br><span class="line">      0.5f, -0.5f,  0.5f,</span><br><span class="line">      -0.5f,  0.5f,  0.5f,</span><br><span class="line">      0.5f,  0.5f,  0.5f,</span><br><span class="line">      // BACK</span><br><span class="line">      -0.5f, -0.5f, -0.5f,</span><br><span class="line">      -0.5f,  0.5f, -0.5f,</span><br><span class="line">      0.5f, -0.5f, -0.5f,</span><br><span class="line">      0.5f,  0.5f, -0.5f,</span><br><span class="line">      // LEFT</span><br><span class="line">      -0.5f, -0.5f,  0.5f,</span><br><span class="line">      -0.5f,  0.5f,  0.5f,</span><br><span class="line">      -0.5f, -0.5f, -0.5f,</span><br><span class="line">      -0.5f,  0.5f, -0.5f,</span><br><span class="line">      // RIGHT</span><br><span class="line">      0.5f, -0.5f, -0.5f,</span><br><span class="line">      0.5f,  0.5f, -0.5f,</span><br><span class="line">      0.5f, -0.5f,  0.5f,</span><br><span class="line">      0.5f,  0.5f,  0.5f,</span><br><span class="line">      // TOP</span><br><span class="line">      -0.5f,  0.5f,  0.5f,</span><br><span class="line">      0.5f,  0.5f,  0.5f,</span><br><span class="line">      -0.5f,  0.5f, -0.5f,</span><br><span class="line">      0.5f,  0.5f, -0.5f,</span><br><span class="line">      // BOTTOM</span><br><span class="line">      -0.5f, -0.5f,  0.5f,</span><br><span class="line">      -0.5f, -0.5f, -0.5f,</span><br><span class="line">      0.5f, -0.5f,  0.5f,</span><br><span class="line">      0.5f, -0.5f, -0.5f,</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  FloatBuffer cubeBuff;</span><br><span class="line">  float xRot = 0.0f;</span><br><span class="line">  float yRot = 0.0f;</span><br><span class="line"></span><br><span class="line">  public CubeRenderer()&#123;</span><br><span class="line">    cubeBuff = makeFloatBuffer(box);//转换为float数组</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @Override public void onSurfaceChanged(GL10 gl, int width, int height) &#123;</span><br><span class="line">    super.onSurfaceChanged(gl, width, height);</span><br><span class="line">    // 设置透视范围</span><br><span class="line">    GLU.gluPerspective(gl,45.0f,((float)width)/height,0.1f,10f);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @Override public void onDrawFrame(GL10 gl) &#123;</span><br><span class="line">    super.onDrawFrame(gl);</span><br><span class="line"></span><br><span class="line">    gl.glMatrixMode(GL10.GL_MODELVIEW);// 切换至模型观察矩阵</span><br><span class="line">    gl.glLoadIdentity();// 重置当前的模型观察矩阵</span><br><span class="line">    GLU.gluLookAt(gl,0f,0f,3f,0f,0f,0f,0f,1f,0f);//设置视点和模型中心位置</span><br><span class="line"></span><br><span class="line">    gl.glVertexPointer(3,GL10.GL_FLOAT, 0,cubeBuff);//设置顶点数据</span><br><span class="line">    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);</span><br><span class="line"></span><br><span class="line">    gl.glRotatef(xRot,1f,0f,0f);// 绕着(0,0,0)与(1,0,0)即x轴旋转</span><br><span class="line">    gl.glRotatef(yRot,0f,1f,0f);</span><br><span class="line"></span><br><span class="line">    gl.glColor4f(1.0f,0f,0f,1.0f);//设置颜色，红色</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,4);//绘制正方形FRONT面</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,4,4);</span><br><span class="line"></span><br><span class="line">    gl.glColor4f(0f,1.0f,0f,1.0f);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,8,4);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,12,4);</span><br><span class="line"></span><br><span class="line">    gl.glColor4f(0f,0f,1.0f,1.0f);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,16,4);</span><br><span class="line">    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,20,4);</span><br><span class="line"></span><br><span class="line">    xRot += 1.0f;</span><br><span class="line">    yRot += 0.5f;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  /**</span><br><span class="line">   * 将float数组转换为存储在字节缓冲数组</span><br><span class="line">   * @param arr</span><br><span class="line">   * @return</span><br><span class="line">   */</span><br><span class="line">  public FloatBuffer makeFloatBuffer(float[] arr)&#123;</span><br><span class="line">    // 分配缓冲空间，一个float占4个字节</span><br><span class="line">    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(arr.length*4);</span><br><span class="line">    // 设置字节顺序，其中ByteOrder.nativeOrder()是获取本机字节顺序</span><br><span class="line">    byteBuffer.order(ByteOrder.nativeOrder());</span><br><span class="line">    // 转换为float型</span><br><span class="line">    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();</span><br><span class="line">    // 添加数据</span><br><span class="line">    floatBuffer.put(arr);</span><br><span class="line">    // 设置数组的起始位置</span><br><span class="line">    floatBuffer.position(0);</span><br><span class="line">    return floatBuffer;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>效果图：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/3110861-b31c7393b4dd12a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="立方体.png"></p>
<p><a href="http://git.oschina.net/zaitingma/codes/5ymp4v1t0eqk2xf93cizj71" target="_blank" rel="noopener">代码下载</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/Android/Android-MimeTypeMap使用--MIME类型/" rel="next" title="Android-MimeTypeMap使用--MIME类型">
                <i class="fa fa-chevron-left"></i> Android-MimeTypeMap使用--MIME类型
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/Android/Android-RecyclerView使用/" rel="prev" title="Android-RecyclerView使用">
                Android-RecyclerView使用 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
